package com.yujistu.activity;

import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.andexert.library.RippleView;
import com.dd.CircularProgressButton;
import com.yujistu.R;

/**
 * Created by Win on 2015/11/5.
 */
public class ChangePwdActivity extends BaseActivity implements RippleView.OnRippleCompleteListener {

    EditText  motifyPwdET;
    EditText  newPwdET;
    EditText  newPwdsET;

    RippleView  detimeRV;
    CircularProgressButton  detimeCPB;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_password);

        InitViews();
    }

    ImageView  backIV;
    TextView   titleTV;
    private void InitViews() {
        backIV = (ImageView)findViewById(R.id.backIv);
        backIV.setVisibility(View.VISIBLE);
        backIV.setOnClickListener(mOnClickListener);
        titleTV = (TextView)findViewById(R.id.tv_title_title);
        titleTV.setVisibility(View.VISIBLE);
        titleTV.setText(R.string.change_password);

        final TextInputLayout  motifyTIL= (TextInputLayout) findViewById(R.id.modify_pwd);
        final TextInputLayout  newTIL= (TextInputLayout) findViewById(R.id.new_pwd);
        final TextInputLayout  newsTIL= (TextInputLayout) findViewById(R.id.new_pwds);

        motifyPwdET = motifyTIL.getEditText();
        newPwdET = newTIL.getEditText();
        newPwdsET = newsTIL.getEditText();

        detimeRV = (RippleView)findViewById(R.id.determineRV);
        detimeRV.setOnRippleCompleteListener(this);
    }

    View.OnClickListener mOnClickListener = new View.OnClickListener(){

        @Override
        public void onClick(View v) {
          switch (v.getId()){
              case R.id.backIv:
                  finish();
                  break;
          }
        }
    };

    @Override
    public void onComplete(RippleView rippleView) {
        switch (rippleView.getId()){
            case R.id.determineRV:
                checkInfoSubmit();
                break;
        }
    }

    private void checkInfoSubmit() {
        String oldPwd = motifyPwdET.getText().toString();
        String newPwd = newPwdET.getText().toString();
        String newPwds = newPwdsET.getText().toString();
        if(isLengthValid(motifyPwdET) && isLengthValid(newPwdET) && isLengthValid(newPwdsET) && isSame()){

            motifyPWD();
        }
    }

    private boolean isLengthValid(EditText et) {
        String  content = et.getText().toString();
        if(!TextUtils.isEmpty(content) && content.length()>5 || content.length()<21){
            return true;
        }
        return false;
    }

    private boolean isSame() {
        String newPwd = newPwdET.getText().toString();
        String newPwds = newPwdsET.getText().toString();
        if(newPwd.equals(newPwds)){
            return true;
        }else {
            toast("两次输入密码不一致", 2000);
            return false;
        }
    }

    private void motifyPWD() {

    }


}
